package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.system.domain.MaterialCertificationRules;
import com.pureut.system.domain.dto.MaterialCertificationRulesDetailDto;
import com.pureut.system.domain.vo.MaterialCertificationRulesVo;
import com.pureut.system.service.IMaterialCertificationRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2024-12-04 13:04:04
 * @Desc: 物料认证规则Controller
 */
@RestController
@RequestMapping("/materiel/approve/rule")
public class MaterialCertificationRulesController  extends BaseController {

    /**
     * 物料认证规则Service
     */
    @Resource
    private IMaterialCertificationRulesService materialCertificationRulesService;

    /**
     * 查询物料认证规则列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialCertificationRules-list")
    @GetMapping("/list")
    public TableDataInfo list(MaterialCertificationRulesVo materialCertificationRulesVo) {
        startPage();
        return getDataTable(materialCertificationRulesService.queryPage(materialCertificationRulesVo));
    }



    /**
     * 获取物料认证规则详细信息
     * @param: id 物料认证规则主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("materialCertificationRules-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        MaterialCertificationRulesDetailDto materialCertificationRulesDetailDto=new MaterialCertificationRulesDetailDto();
        BeanUtil.copyProperties(materialCertificationRulesService.getById(id), materialCertificationRulesDetailDto);

        return AjaxResult.success(materialCertificationRulesDetailDto);
    }

    /**
     * 新增物料认证规则
     * @param: materialCertificationRules 物料认证规则对象
     * @return: Json工具类对象
     */
    @Log(title = "新增物料认证规则", businessType = BusinessType.INSERT)
    //    @SaCheckPermission("materialCertificationRules-add")
    @PostMapping
    public AjaxResult add(@RequestBody MaterialCertificationRulesVo materialCertificationRulesVo) {
        return toAjax(materialCertificationRulesService.save(materialCertificationRulesVo));
    }

    /**
     * 修改物料认证规则
     * @param: materialCertificationRules 物料认证规则对象
     * @return: Json工具类对象
     */
    @Log(title = "修改物料认证规则", businessType = BusinessType.UPDATE)
    //    @SaCheckPermission("materialCertificationRules-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody MaterialCertificationRulesVo materialCertificationRulesVo) {
        return toAjax(materialCertificationRulesService.updateById(materialCertificationRulesVo));
    }

    /**
     * 删除物料认证规则
     * @param: id 物料认证规则主键
     * @return: Json工具类对象
     */
    @Log(title = "删除物料认证规则", businessType = BusinessType.DELETE)
    //    @SaCheckPermission("materialCertificationRules-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(materialCertificationRulesService.removeByIds(Arrays.asList(ids)));
    }
}
